/**
 * SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
 * SPDX-License-Identifier: Mulan PSL v2
 */

/**
 * 静态文件下载
 * @param {String} url
 * @param {String} fileName
 */

export default function downloadFileStatic (url: string, fileName = '') {
    if (!url) {
        return;
    }
    let link = document.createElement('a');
    link.href = url;
    link.download = fileName || getFileName(url);
    document.body.appendChild(link);
    link.click();
    window.URL.revokeObjectURL(link.href);
    document.body.removeChild(link);
}

// 获取文件名
function getFileName(path: string){
    let pos = path.lastIndexOf('/');
    return pos < 0 ? path : path.substring(pos + 1);
}
